<template>
  <el-checkbox-group v-model="groupValue" v-bind="$attrs" v-on="$listeners">
    <slot/>
  </el-checkbox-group>
</template>

<script>

export default {
    name: 'mc-checkbox-group',
    data () {
        return {
            //实现了双向绑定 坑爹的 不给值就报空指针
            groupValue : this.value ? this.value.split(",") : []
        }
    },
    watch:{
        //发现变更，把父组件的v-model给改变
        groupValue(newValue){
            this._assist(newValue);
            this.$emit("input",newValue.join(","))
        },
        value(newValue){
            this._assist(newValue);
            this.groupValue = newValue?newValue.split(","):[]
        }
    },
    //此处的value 就是父亲的v-model
    props: ['value'],
    mounted () {},
    methods:{
      _assist(val){
        if(val===true){
          console.error("warn:复选框组渲染错误,内部的复选框请不要初始化选中(去掉checked),如果要给初始化值请用逗号分割多个值")
        }
      }

    }
}
</script>

<style lang="scss">

</style>
